Program Q2trj
use var
use type
implicit none
integer  :: i,ss,step,y,ioerr = 0, first, last, ff, delta, nn
character*20 :: string
real, allocatable :: qsingle(:,:)
Character(len=10) :: namefile
Character :: tt

call input()
call initial(0)
Print *, "enter the name of binary file"
read(*,*)namefile

OPEN ( 111 , FILE =namefile,form='UNFORMATTED',access='SEQUENTIAL',status='old')

call rtraj()
!call position_NP()
if (droplet) call make_np_droplet()
if (channel) call make_np_channel()
if (cylinder) call make_np_cylinder()
call define_parameter()

Print *," last qmga 1; last paraview 2; last Q 3; other 4; only qmga 5; only paraview 6"
read(*,*) nn

if (nn==1) then
   call qmga(frame)
elseif (nn==2) then
   call paraview_eigen_new(frame)
elseif (nn==3) then
   call  wtraj(1,0,0)
elseif (nn>=4) then
Print *, "enter first and last frame and delta"
read(*,*) first, last, delta
allocate (qsingle(6,tnodes))
rewind(111)
ff = first
do
read(111,IOSTAT=ioerr)string
if (ioerr == 0) then
   read(111)frame,ss,step,y
   read(111)ISEED  
   read(111)trj_E
   read(111)NP_position
   read(111)qsingle
   if (frame==ff) then
      q=qsingle
      call initial(0)
      Do i=1,number_NP
         print *, "O",NP_position(:,i)
      enddo
      if (droplet) call make_np_droplet()
      if (channel) call make_np_channel()
      call define_parameter()
      print *, "frame ", frame
      q = qsingle 
      if (nn==4.or.nn==5) call qmga(frame)
      if (nn==4.or.nn==6) call paraview_eigen_new(frame)
      ff = ff + delta
      if (ff>last) exit
   endif
else
   exit
endif
enddo
deallocate(qsingle)
endif
end program
